#region File Description
//-----------------------------------------------------------------------------
// MainForm.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System.Windows.Forms;
using SharedCongkak;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System.Data;
using System.Linq;
#endregion

namespace CongkakEditor
{
    // System.Drawing and the XNA Framework both define Color types.
    // To avoid conflicts, we define shortcut names for them both.
    using GdiColor = System.Drawing.Color;
    using XnaColor = Microsoft.Xna.Framework.Graphics.Color;

    
    /// <summary>
    /// Custom form provides the main user interface for the program.
    /// In this sample we used the designer to add a splitter pane to the form,
    /// which contains a SpriteFontControl and a SpinningTriangleControl.
    /// </summary>
    public partial class MainForm : Form
    {
        ContentBuilder contentBuilder;
        ContentManager content;

        public MainForm()
        {
            InitializeComponent();
            contentBuilder = new ContentBuilder();
            content = new ContentManager(levelControl.Services, contentBuilder.OutputDirectory);


            levelControl.OnHighlightedHoleChange +=
                (o, args) =>
                {
                    propertyGrid.SelectedObject = o;
                    propertyGrid.Refresh();
                };
        }

        private void newStoreButton_Click(object sender, System.EventArgs e)
        {
            levelControl.CreateNewStore();
        }

        private void newHoleButton_Click(object sender, System.EventArgs e)
        {
            levelControl.CreateNewHole();
        }

        private void saveButton_Click(object sender, System.EventArgs e)
        {
            DialogResult result = saveFileDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                levelControl.Serialize(saveFileDialog.FileName);
            }
        }

        private void OpenButton_Click(object sender, System.EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string assetName = openFileDialog.SafeFileName.Split('.').First();
                string assetPath = "C:\\Users\\Khalid\\Documents\\Visual Studio 2008\\Projects\\Congkak\\Congkak\\Content\\Texture\\";
                contentBuilder.Add(assetPath + "Hole.tga", "texture/hole",
                    "TextureImporter", "TextureProcessor");
                contentBuilder.Add(assetPath + "HoleSelected.tga", "texture/holeselected",
                    "TextureImporter", "TextureProcessor");
                contentBuilder.Add(assetPath + "Store.tga", "texture/store",
                    "TextureImporter", "TextureProcessor");
                contentBuilder.Add(assetPath + "StoreSelected.tga", "texture/storeselected",
                    "TextureImporter", "TextureProcessor");

                contentBuilder.Add(openFileDialog.FileName, assetName, null, null);
                string buildError = contentBuilder.Build();
                Cursor = Cursors.WaitCursor;
                if (string.IsNullOrEmpty(buildError))
                {
                    // If the build succeeded, use the ContentManager to
                    // load the temporary .xnb file that we just created.
                    levelControl.Deserialize(assetName, content);
                    //LevelData level = content.Load<LevelData>(assetName);
                }
                else
                {
                    // If the build failed, display an error message.
                    MessageBox.Show(buildError, "Error");
                }
                Cursor = Cursors.Arrow;
            }
        }



    }
}
